/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package Profile;

import Address.AddressBean;
import Country.CountryBean;
import Department.DepartmentBean;
import Designation.DesignationBean;
import Employee.EmployeeBean;
import State.StateBean;
import User.UserBean;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author mishra
 */
public class Profile extends HttpServlet {

    
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException, SQLException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        try {
                int UId=Integer.parseInt(request.getParameter("uid"));
                EmployeeBean eb=Employee.Query.viewSpecific("USER_ID", UId);
                if(eb.getEmployeeId()!=0){
                AddressBean ab =eb.getAddressBean();
                StateBean sb =ab.getStateBean();
                CountryBean cb = ab.getCountryBean();
                DepartmentBean db = eb.getDepartmentBean();  
                DesignationBean dib =eb.getDesignationBean();
                UserBean ub = eb.getUserBean();
            
            out.println("<div class='box-content'><div class='cl'>");
            
            out.println("<div class='pull-left'><h3>User Profile</h3>");                        
            out.println("<div class='control-group'><div class='controls'><ul class='gallery'><li><span class='preview' id='photo1'><img id='"+eb.getPhoto()+"' style='height: 115px; width: 90px; cursor: -webkit-zoom-in;' title='"+eb.getPhoto()+"' src='"+Documents.Query.getPhoto(eb.getPhoto())+"' alt='"+eb.getPhoto()+"'></span></li></ul></div></div>");                            
            out.println("</div>");                                
            
            out.println("<div class='details pull-left userprofile'>");  
            
            out.println("<table class='table table-striped table-detail'><tbody><tr>");                            
            out.println("<tr><th>Username:</th>");                            
            out.println("<td>"+ub.getEmployeeName()+"</td></tr>");                                
            out.println("<tr><th>Register date:</th>");                                
            out.println("<td>"+ub.getDor()+"</td></tr>");                                
            out.println("<tr><th>User Type:</th>");                                
            out.println("<td><span class='label label-success'>"+ub.getUserType()+"</span></td></tr>");                                
            out.println("<tr><th>Email:</th>");                                
            out.println("<td><a href='#'>"+ub.getEmail()+"</a></td></tr>");  
            out.println("<tr><th>Employee Status:</th>");
            String val="";
                  if(ub.getUserStatus()==1)
                  {
                      val="<span class='label label-sucess' style='top: -6px;'>Approved</span>";
                  }
                  else if(ub.getUserStatus()==0)
                  {
                     val="<span class='label label-warning' style='top: -6px;'>Waiting</span>";
                  }
                  else
                  {
                     val="<span class='label label-important' style='top: -6px;'>Rejected</span>"; 
                  }
            out.println("<td>"+val+"</td></tr>"); 
            out.println("</tbody></table></div></div>"); 
                
            out.println("<h3 class='divide'>Basic information</h3>");                                
            out.println("<table class='table table-striped table-detail'>");                                
            out.println("<tbody><tr>");                                
            out.println("<tr><th>Pan Card Number:</th>");                                
            out.println("<td>"+eb.getPanCard()+"</td></tr>");                                
            out.println("<th>Mobile Number:</th>");                                
            out.println("<tr><td>"+eb.getMobile()+"</td></tr>");                                
            out.println("<th>Phone Number:</th>");                                
            out.println("<td>"+eb.getPhone()+"</td></tr>");                                
            out.println("<tr><th>Gender:</th>");                                
            out.println("<td>"+eb.getGender()+"</td></tr>");                                
            out.println("<tr><th>Higher Qualification:</th>");                                
            out.println("<td>"+eb.getHigherQuali()+"</td></tr>");                                
            out.println("<tr><th>Designation:</th>");                                
            out.println("<td>"+dib.getDesignation()+"</td></tr>");                                
            out.println("<tr><th>Department:</th>");                                
            out.println("<td>"+db.getDepartmentName()+"</td></tr>");                                
            out.println("<tr><th>Job Details:</th>");                                
            out.println("<td>"+eb.getJobdetails()+"</td></tr>");                                
            out.println("<tr><th>Father Name:</th>");                                
            out.println("<td>"+eb.getEmployeeFatherName()+"</td></tr>");                                
            out.println("<tr><th>Address:</th>");                                
            out.println("<td>"+ab.getAddress1()+""+ab.getAddress2()+"</td></tr>");                                
            out.println("<tr><th>Pin Code:</th>");                                
            out.println("<td>"+ab.getPinCode()+"</td></tr>");
            out.println("<tr><th>State:</th>");                                
            out.println("<td>"+sb.getStateName()+"</td></tr>");
            out.println("<tr><th>Country:</th>");                                
            out.println("<td>"+cb.getCountryName()+"</td></tr>");
                                                   
            out.println("</tbody></table></div>"); 
            }else
            {
               out.println("<tr>");
               out.println("<td colspan='3'>");
               out.println("<b>No Record Found</b>");
               out.println("</td>");
               out.println("</tr>");
            }
        }catch(Exception e){
            out.println(e);
        } finally {
            out.close();
        }
    }

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /**
     * Handles the HTTP <code>GET</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        try {
            processRequest(request, response);
        } catch (SQLException ex) {
            Logger.getLogger(Profile.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    /**
     * Handles the HTTP <code>POST</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        try {
            processRequest(request, response);
        } catch (SQLException ex) {
            Logger.getLogger(Profile.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    /**
     * Returns a short description of the servlet.
     *
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>

}
